package com.alibaba.aliper.server.controller.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.aliper.server.model.impl.AliperServer;
import com.alibaba.aliper.server.model.interfaces.AliperView;

/**
 * Servlet implementation class AliperImager
 */
public class AliperImager extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AliperImager() {
        super();
    }

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String project = request.getParameter("project");
		String agent = request.getParameter("agent");
		String chart = request.getParameter("chart");
		if(agent != null && chart != null){
			response.setContentType("image/jpeg");
			AliperView view = AliperServer.getAliperServer();
			byte[] data = view.getAgent(project,agent).getChart(chart).getImage();
			response.getOutputStream().write(data);
		}
	}

}
